Skip to content

fix: invoke cli by program name in generated completion scripts#139

Merged
AmirSa12 merged 4 commits into
mainfrom
fix/command-exec
Jul 10, 2026
Merged

fix: invoke cli by program name in generated completion scripts#139
AmirSa12 merged 4 commits into
mainfrom
fix/command-exec

Conversation

@AmirSa12

@AmirSa12 AmirSa12 commented Jul 7, 2026

Copy link
Copy Markdown
Member

closes #135

The adapters baked a reconstructed launch path (process.execPath + execArgv + argv[1]) into the generated completion scripts, which assumes a node/bun script.js invocation. That path is invalid for compiled single-file binaries (bun build --compile, Node SEA, etc.), where argv[1] is a virtual/duplicated path and this silently breaking tab completion. the commander, cac, and citty adapters now invoke the CLI by its program name, which the shell already resolves via PATH/alias/function.

@changeset-bot

changeset-bot Bot commented Jul 7, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: ed81535

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@bomb.sh/tab Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jul 7, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@bomb.sh/tab@139

commit: ed81535

@dreyfus92 dreyfus92 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hey @AmirSa12 everything looks sound, i left a tiny nit and also we should consider that this silently changes the dev workflow source <(pnpm tsx cli.ts completezsh) used to work without installing, now the bin needs to be on PATH. fine tradeoff, but worth a line in the changeset or readme so people don't get bitten by it.

Comment thread src/citty.ts Outdated
Comment thread src/citty.ts Outdated
@techzealot

Copy link
Copy Markdown

hey @AmirSa12 everything looks sound, i left a tiny nit and also we should consider that this silently changes the dev workflow source <(pnpm tsx cli.ts completezsh) used to work without installing, now the bin needs to be on PATH. fine tradeoff, but worth a line in the changeset or readme so people don't get bitten by it.


The concern about source <(pnpm tsx cli.ts complete zsh) silently breaking is valid in theory, but in practice the recommended dev workflow using a shell function works with both old and new versions of tab.

When you define my-cli() { pnpm tsx src/index.ts "$@"; } and run source <(my-cli complete zsh), the generated completion script binds to my-cli via compdef. When Tab triggers the callback my-cli complete -- ..., the shell resolves it to the function, which forwards all arguments to pnpm tsx. This means no build, no PATH changes, and no installation is needed — the function is session-scoped and disappears when you close the terminal.

This works across all supported shells (zsh, bash, fish, powershell) since eval resolves shell functions in every shell. The only difference is the function definition syntax per shell.

I suggest adding the following dev workflow section to the docs:


Development Workflow

For local development, define a shell function to run the CLI from source. Copy the snippet for your shell:
Replace my-cli with your program name and adjust the source path if needed.

zsh

my-cli() { pnpm tsx src/index.ts "$@"; }
source <(my-cli complete zsh)

bash

my-cli() { pnpm tsx src/index.ts "$@"; }
source <(my-cli complete bash)

fish

function my-cli; pnpm tsx src/index.ts $argv; end
source (my-cli complete fish | psub)

powershell

function my-cli { pnpm tsx src/index.ts $args }
my-cli complete powershell | Out-String | Invoke-Expression

Co-authored-by: Roman <dev@rman.dev>
@AmirSa12

Copy link
Copy Markdown
Member Author

Thank you all!
I'll merge this and change the docs in a separate PR.

@AmirSa12 AmirSa12 merged commit e01ce05 into main Jul 10, 2026
12 checks passed
@AmirSa12 AmirSa12 deleted the fix/command-exec branch July 10, 2026 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Shell completion scripts use fragile runtime-specific exec path construction (x) — should use program name instead

4 participants